package com.cuit.qx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuit.qx.bean.WeatherStation;
import com.cuit.qx.dao.WeatherStationMpper;
import com.cuit.qx.service.WeatherStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author:wjd
 * @Description: 气象站点Service
 * @date:Created in 16:53 2020/9/17
 * @Modified By:
 */
@Service
public class WeatherStationServiceImpl extends ServiceImpl<WeatherStationMpper, WeatherStation>
        implements WeatherStationService {

    @Autowired
    WeatherStationMpper mapper;


    @Override
    public int insertWeather(WeatherStation weatherStation) {
        return mapper.insert(weatherStation);

    }

    @Override
    public List<WeatherStation> getAllWeatherStation(int pageNo, int pageSize) {
        IPage<WeatherStation> userPage = new Page<>(pageNo, pageSize);//参数一是当前页，参数二是每页个数
        userPage = mapper.selectPage(userPage, null);
        return userPage.getRecords();
    }

    @Override
    public int updateWeather(WeatherStation weatherStation) {
        return mapper.updateWeatherId(weatherStation);
    }

    @Override
    public int updateWeatherList(List<WeatherStation> weatherStations) {
        return mapper.updateWeatherForeach(weatherStations);
    }

    @Override
    public List<WeatherStation> getWeather(Integer pageNo, Integer pageSize, String stationNumber, String stationName, String stationCounty, String stationType) {
        return mapper.selectFoggyWeather(pageNo, pageSize, stationNumber, stationName, stationCounty, stationType);
    }

    @Override
    public List<WeatherStation> getWeatherByStationNumber(List<String> stationNumber) {
        return mapper.selectWeatherByStationNumber(stationNumber);
    }

    @Override
    public int deleteWeatherById(String id) {
        return mapper.deleteWeatherById(id);
    }

    @Override
    public int deleteWeatherByIds(String[] ids) {
        int i = mapper.deleteWeatherByIds(ids);
        return i;
    }

    @Override
    public int boolWeatherStationNumber(String stationNumber) {
        int num = mapper.selectWeatherStationNumber(stationNumber);
        return num;
    }

    @Override
    public List<WeatherStation> getBySateWeather() {
        return mapper.getBySateWeather();
    }

    @Override
    public int getFoggyWeatherNum(String stationNumber, String stationName, String stationCounty, String stationType) {
        return mapper.selectFoggyWeatherNum(stationNumber, stationName, stationCounty, stationType);
    }

    @Override
    public List<String> getCounty() {
        return mapper.getCounty();
    }

    @Override
    public List<Map<String, Object>> getMapSiteAll() {
        return mapper.getMapStieAll();
    }

    @Override
    public WeatherStation getStationInfoByName(String station) {
        QueryWrapper<WeatherStation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("station_number",station);
        WeatherStation weatherStation = this.mapper.selectOne(queryWrapper);
        return weatherStation;
    }


}
